﻿@using KMF.WebUI.Areas.KMFadmin.Models
@using KMF.WebUI.Areas.KMFadmin.CustomHelpers
@model IEnumerable<KMF.Common.ProviderListDto>
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/KMFadmin/Views/Shared/_layout.cshtml";
}

<div class="toolBox">
    @Html.ToolBox(new List<object> { new Add { ClassCss = "Add", ActionName = "/KMFadmin/AdminProvider/Add" } })
</div>
<div class="box-search">
    @using(Html.BeginForm("SearchProvider", "AdminProvider"))
    {
        @Html.TextBox("keyword")
        <input type="submit" value="Tìm kiếm" />
    }
</div>
<table class="table-odd table-plist">
    <tr>
        <th style="width: 30px;">STT</th>
        <th style="width: 50px;">Hình ảnh</th>
        <th>Tên</th>
        <th style="width: 50px;">Vị trí</th>
        <th style="width: 30px;">Tab</th>
    </tr>

    @{
        if (Model.Any())
        {
            foreach (var item in Model)
            {
                <tr>
                    <td align="center">@item.STT</td>
                    <td align="center">
                        <img src="/upload/ProviderImages/@item.ImagePath?width=45&height=45" width="45" height="45"/>
                    </td>
                    <td>
                        <a href="@Url.Action("Edit", "AdminProvider", new {id = @item.Id})">@item.Name</a>
                        <div class="info-ad-qv">
                            <a href="@Url.Action("Edit", "AdminProvider", new {id = @item.Id})">Sửa</a> | 
                            <a href="">Sửa nhanh</a> | 
                            <a href="javascript:void(0);" onclick="DeleteColor(@item.Id)" class="ad-qv-txt2">Xóa</a> | 
                            <a href="">Xem</a>
                        </div>
                    </td>
                    <td>
                        @item.Ordering
                    </td>
                    <td align="center">
                        <input type="checkbox" checked="@item.ShowHome" />
                    </td>
                </tr>
            }
        }
    }
</table>
<div class="p-paging">
    @Html.PageLinks((PageInfo)ViewBag.PageInfo, i => Url.Action("Index", "AdminProvider", new { page = i }))
</div>
@section scripts
{
    <script type="text/javascript">
        function DeleteColor(id) {
            if (confirm('Bạn có chăc chắn muốn xóa !')) {
                $.ajax({
                    url: '/KMFadmin/AdminProvider/DeleteProvider',
                    data: { id: id },
                    success: function(data) {
                        if (data) {
                            alert('Xóa provider thành công!');
                            window.location = '/KMFadmin/AdminProvider';
                        } else {
                            alert('Xóa provider thất bại!');
                        }
                    },
                    error: function() {
                        alert('Đã có lỗi xảy ra!');
                    }
                });
            }
        }
    </script>
}
